<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Java 文档搜索</title>
</head>
<body>
<div class="container">
    <div class="header">
        <input type="text">
        <button id="search-btn">搜索</button>

    </div>

    <div class="result">
        <!-- <div class="item">
            <a href="#">我是标题</a>
            <div class="desc">我是一段描述fsra agarg tdshths bfra fef bstvr dfva rgbstsrafv cvarevreavrrf varvregthaed awa frbearwbd bqdbnjnjkneaf jadn sna  fjnef iek fweenjf </div>
            <div class="url">http://www.baidu.com</div>
        </div>
        <div class="item">
            <a href="#">我是标题</a>
            <div class="desc">我是一段描述fsra agarg tdshths bfra fef bstvr dfva rgbstsrafv cvarevreavrrf varvregthaed awa frbearwbd bqdbnjnjkneaf jadn sna  fjnef iek fweenjf</div>
            <div class="url">http://www.baidu.com</div>
        </div>
        <div class="item">
            <a href="#">我是标题</a>
            <div class="desc">我是一段描述fsra agarg tdshths bfra fef bstvr dfva rgbstsrafv cvarevreavrrf varvregthaed awa frbearwbd bqdbnjnjkneaf jadn sna  fjnef iek fweenjf</div>
            <div class="url">http://www.baidu.com</div>
        </div>
        <div class="item">
            <a href="#">我是标题</a>
            <div class="desc">我是一段描述fsra agarg tdshths bfra fef bstvr dfva rgbstsrafv cvarevreavrrf varvregthaed awa frbearwbd bqdbnjnjkneaf jadn sna  fjnef iek fweenjf</div>
            <div class="url">http://www.baidu.com</div>
        </div> -->
    </div>
</div>
<style>
    *{
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    html,body{
        height: 100%;
        background-image: url(image/src=http___pic1.win4000.com_wallpaper_d_550a667da1deb.jpg&refer=http___pic1.win4000.webp);
        background-repeat: no-repeat;
        background-position: center center;
        background-size: cover;
    }

    .container{
        width: 67.5%;
        height: 100%;
        margin: 0 auto;
        background-color:rgba(255,255,255,0.8);
        border-radius: 10px;
        padding: 20px;
        overflow: auto;
    }
    .header{
        width: 100%;
        height: 50px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .header>input{
        width: 870px;
        height: 50px;
        font-size: 22px;
        line-height: 50px;
        padding-left: 10px;
        border-radius: 10px;
    }
    .header>button{
        width: 100px;
        height: 50px;
        background-color: rgb(30, 144, 255);
        color: #fff;
        font-size: 22px;
        line-height: 50px;
        border-radius: 10px;
        border: none;
    }
    .header>button:active{
        background: gray;
    }

    .result .count{
        color: grey;
        margin-top: 20px;
    }
    .item {
        width: 100%;
        margin-top: 20px;
    }
    .item a {
        display: block;
        height: 40px;

        font-size: 22px;
        line-height: 40px;
        font-weight: 700;
        color: rgb(30, 144, 255);
    }
    .item .desc{
        font-size: 18px;
    }
    .item .url{
        font-size: 18px;
        color: rgb(0, 128, 0);
    }
    .item .desc i{
        color:red;
        font-style:normal;
    }

</style>
    <script src="js/jquery.js"></script>

    <script>
        let button=document.querySelector("#search-btn");
        button.onclick=function(){
            let input=document.querySelector(".header input");
            let query=input.value;
            console.log("query: "+query);
            $.ajax({
                type:"GET",
                url:"searcher?query="+query,
                success: function(data,status){
                    buildResult(data);
                }
            })
        }
        function buildResult(data){
            let result=document.querySelector('.result');
            result.innerHTML='';
            let countDiv=document.createElement('div');
            countDiv.innerHTML='已为你找到'+data.length+'个结果！';
            countDiv.className='count';
            result.appendChild(countDiv);
            for(let item of data){
                let itemDiv=document.createElement('div');
                itemDiv.className='item';

                let title=document.createElement('a');
                title.href=item.url;
                title.innerHTML=item.title;
                title.target='_blank';
                itemDiv.appendChild(title);

                let desc=document.createElement('div');
                desc.className='desc';
                desc.innerHTML=item.desc;
                itemDiv.appendChild(desc);

                let url=document.createElement('div');
                url.className='url';
                url.innerHTML=item.url;
                itemDiv.appendChild(url);

                result.appendChild(itemDiv);
            }
        }
    </script>
</body>
</html>